<?php 
//中间的基础控制器
	
	namespace Home\Controller;
	use Think\Controller;
	class CommonController extends Controller{
		//相当于构造函数
		public function _initialize()
		{

			$paths = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
			// var_dump($paths);
			if (in_array($paths, C('AUTH_PATHS'))) {
				if (!isset($_SESSION['id'])) {
					$this->error('请先登录',U('home/index/index'));
				}
			}
		}


		public function autoAdd($table,$filed,$num,$id)
		{
			//自增或者自减某个字段的值 有点难以理解
			$sql = "update ".$table." set " .$filed ."=".$filed.$num ." where id='{$id}'";
			
    		M()->execute($sql);
		}

		public function getHotView()
		{
			//获取热门的查看数最多的十条
			$sql = "select * from question order by view_num desc limit 10";

			$hotView = M()->query($sql);

    		$this->assign('hotView',$hotView);
		}


		public function getHotanswer()
		{
			//获取热门的回答数最多的十条
			$sql = "select * from question order by answer_num desc limit 10";
			
			$hotAnswer = M()->query($sql);
			// var_dump($hotAnswer);
    		$this->assign('hotAnswer',$hotAnswer);
		}


		public function getHotuser()
		{
			//获取热门的十个用户
			$sql = "select * from user order by answer_num desc limit 12";
			
			$hotUser = M()->query($sql);


    		$this->assign('hotUser',$hotUser);
		}






}






 ?>